import QtQuick 2.0
import VPlay 2.0
import QtQuick.Controls 1.4

Rectangle {
  id: battery

  property int max_power: 4 //4 is full
  property int const_battery_width: 44
  property int battery_width: 0
  property var battery_colors: ["red", "red", "#c2e297", "#97ea5c", "#00ff15"]

  function setPower(power) {
    battery_width = const_battery_width / max_power * power

    var index = battery_colors.length > max_power  ? max_power : power
    power_rect.color = battery_colors[index]
  }

  Image {
    source: "../../assets/img/battery_null.png"
    width: 64
    height: 64
  }

  Rectangle {
    id: power_rect
    anchors.left: battery.left
    anchors.leftMargin: 8
    anchors.top: battery.top
    anchors.topMargin: 6
    width: battery_width
    height: 20
    color: "#97ea5c"
  }

//  Timer {
//    interval: 3000
//    //repeat: true
//    //running: true
//    onTriggered: {
//      setPower(3)
//    }
//  }

  Component.onCompleted: {
    setPower(4)
  }
}
